package com.wxtt.android.wxapi;

import android.content.Intent;
import android.os.Bundle;

import com.tencent.mm.sdk.constants.ConstantsAPI;
import com.tencent.mm.sdk.modelbase.BaseReq;
import com.tencent.mm.sdk.modelbase.BaseResp;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
import com.three.WxUtils;
import com.wxtt.android.R;
import com.wxtt.android.common.CommonActivity;

/**
 * 说明：微信回调类
 * <p/>
 * 作者：fanly
 * <p/>
 * 时间：2016/2/25 11:47
 * <p/>
 * 版本：verson 1.0
 */
public class WXEntryActivity extends CommonActivity implements IWXAPIEventHandler{


    private IWXAPI api;

    @Override
    public void onReq(BaseReq baseReq) {

    }

    @Override
    public void onResp(BaseResp baseResp) {
        //分享
        if (baseResp.getType() == ConstantsAPI.COMMAND_SENDMESSAGE_TO_WX){
            switch (baseResp.errCode){
                case BaseResp.ErrCode.ERR_OK:
                    shortToast("分享成功");
                    break;
                case BaseResp.ErrCode.ERR_USER_CANCEL:
                    shortToast("取消分享");
                    break;
                case BaseResp.ErrCode.ERR_AUTH_DENIED:
                    shortToast("认证失败");
                    break;
            }
        }
        finish();
    }

    @Override
    public void onInit(Bundle bundle) {
        super.onInit(bundle);
        api = WxUtils.regToWx(this);
        api.handleIntent(getIntent(),this);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        api.handleIntent(intent,this);
    }

    @Override
    public int setRootView() {
        return R.layout.activity_about;
    }
}
